package com.oceansoft.mobile.econsole.scheduled;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.sys.entity.ApiInfo;
import com.oceansoft.mobile.econsole.modules.sys.entity.ParamInfo;
import com.oceansoft.mobile.econsole.modules.sys.service.IApiInfoService;
import com.oceansoft.mobile.econsole.modules.sys.service.IParamService;

//@Controller
public class ScheduleLoader {

	@Resource
	private IApiInfoService apiInfoService;
	@Resource
	private IParamService paramService;

//	@RequestMapping("monitor")
//	@ResponseBody
	public Result initScheduler(){
		List<ApiInfo> allApiInfo = apiInfoService.findAllApiInfo();
		for(ApiInfo info:allApiInfo){
			List<ParamInfo> params = paramService.findAllParams(info.getId());
			if(info.getTimeInterval()!=0){
			ScheduleTasker scheduleTasker = new ScheduleTasker(info, params,apiInfoService,paramService);
			scheduleTasker.startTask();}
		}
		return new Result();
	}
}
